This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal


Jun 16, 2017, 11:33 AM
13 Posts

Clone ACL Example

  • Category: Domino Designer
  • Platform: All Platforms
  • Release: 9.0.1
  • Role: Developer
  • Tags: ACL Clone Example
  • Replies: 0

Many of our databases evolved complicated ACLs over the years. The databases also require I create a copy and archive the present data to the archive so I needed an easier way to clone the current database's ACL to the archive. Anyway here's some button code that does this task. It excludes -default-, yourself, servers, and those with manager privilege from being cloned.

 

Sub Click(Source As Button)
 ' Clone the ACL of a specified database to another database.
 ' Do not change server entries, etc.
 Dim wk As New NotesUIWorkspace
 Dim session As New NotesSession
 Dim uiDoc As NotesUIDocument
 Dim doc As NotesDocument
 Dim oDb As NotesDatabase    ' Original Database (The one whose ACL is to be cloned)
 Dim cDb As NotesDatabase    ' Target Database (The DB that will have its ACL set the same as the Original Database)
 Dim oAcl As NotesACL       ' ... and so on and so forth. Things begining with "o" is original, "c" is the clone........
 Dim oEntry As NotesACLEntry
 Dim cAcl As NotesACL
 Dim cEntry As NotesACLEntry
 Dim sEntry As NotesACLEntry    ' Saved ACL entry so we can keep track of where we are.
 Dim user As NotesName
 
 Dim rDatabase As Variant
 Dim role As String
 Dim ans As Integer
 
 Set uidoc = wk.CurrentDocument
 Set doc = uidoc.Document
 Set user = New NotesName(Session.Username)
 
 Messagebox "You will be prompted for 2 databases. The first one will be the database whose ACL you want to clone. The second one will be the database whose ACL will be created based on the first database selected" + Chr(13) + Chr(13) + _
 " WARNING - This will wipe out the target database's ACL and replace it with the ACL of the database you want to clone."
 
 rDatabase = wk.prompt(13,"Copy ACL","Select a database whose ACL you would like to clone")
 If Isempty(rDatabase) Then Exit Sub
 Set oDb = New NotesDatabase(rDatabase(0),rDatabase(1))
 If oDb Is Nothing Then
  Messagebox "Input database " + doc.server(0) + "/" + doc.FilePath(0) + " not found"
  Exit Sub
 End If
 
 rDatabase = wk.prompt(13,"Copy ACL","Select the target database whose ACL will be updated")
 If Isempty(rDatabase) Then Exit Sub
 Set cDb = New NotesDatabase(rDatabase(0),rDatabase(1))
 If cDb Is Nothing Then
  Messagebox "Output database " + doc.cServer(0) + "/" + doc.cFilePath(0) + " Not Found"
  Exit Sub
 End If
 If cDb.CurrentAccessLevel <> ACLLEVEL_MANAGER Then
  Messagebox "You do not have manager level access to the output database " + doc.cServer(0) + "/" + doc.cFilePath(0)
  Exit Sub
 End If
 
 ans = Messagebox("This will clone the ACL entries of this database" + Chr(13) + Chr(13) + odb.Title + Chr(13) + odb.Server + "/" + odb.FilePath + Chr(13) + Chr(13) + "to" + _
 Chr(13) + Chr(13) + cdb.Title + Chr(13) + cdb.Server + "/" + cdb.FilePath + Chr(13) + Chr(13) + "ARE YOU SURE?",1,"WARNING!")
 If ans = 2 Then Exit Sub
 
 ' Lets start deleting entries and roles from output database
 Set oAcl = oDb.ACL
 Set cAcl = cDb.ACL
 
 ' delete all the roles
 Forall r In cAcl.Roles
  If r = "" Then Exit Forall
  role = Strright(r,"[")
  role = Strleft(role,"]")
  Call cAcl.DeleteRole(role)
 End Forall
 ' Now copy all roles from the Original Database
 Forall r In oAcl.Roles
  If r = "" Then Exit Forall
  role = Strright(r,"[")
  role = Strleft(role,"]")
  Call cAcl.AddRole(role)
 End Forall
 
 ' Let's get rid of all the ACL entries except for the ones we want to keep.
 Set cEntry = cAcl.GetFirstEntry
 Do While Not cEntry Is Nothing
  Set sEntry = cAcl.GetNextEntry(cEntry)
  If cEntry.Name = "-Default-" Or _ ' Exclude default
  cEntry.IsServer = True Or _     ' Exclude servers
  cEntry.isAdminServer = True Or _ ' Exclude Admin Servers
  cEntry.Level = ACLLEVEL_MANAGER Or _        ' Exclude any current managers. We can get rid of them later.
  cEntry.Name = user.Canonical _ ' Exclude yourself
  Then
   ' Do nothing...........
  Else
   Call cEntry.Remove
  End If
  Set cEntry = sEntry
 Loop
 
 ' Now we copy over all the ACL entries except for the ones left in the target database
 Set oEntry = oAcl.GetFirstEntry
 While Not oEntry Is Nothing
  Set cEntry = cAcl.GetEntry(oEntry.Name)
  If cEntry Is Nothing Then
   Set cEntry = New NotesACLEntry(cAcl,oEntry.Name,oEntry.Level)
   With cEntry
    .CanCreateDocuments = oEntry.CanCreateDocuments
    .CanCreateLSOrJavaAgent = oEntry.CanCreateLSOrJavaAgent
    .CanCreatePersonalAgent = oEntry.CanCreatePersonalAgent
    .CanCreatePersonalFolder = oEntry.CanCreatePersonalFolder
    .CanCreateSharedFolder = oEntry.CanCreateSharedFolder
    .CanDeleteDocuments = oEntry.CanDeleteDocuments
    .canReplicateOrCopyDocuments = oEntry.CanReplicateOrCopyDocuments
    .IsAdminReaderAuthor = oEntry.IsAdminReaderAuthor
    .isAdminServer = oEntry.IsAdminServer
    .isGroup = oEntry.IsGroup
    .isPerson = oEntry.IsPerson
    .ispublicReader = oEntry.IsPublicReader
    .ispublicwriter = oentry.IsPublicWriter
    .isServer = oEntry.IsServer
    .usertype = oEntry.UserType
   End With
   Forall r In oAcl.Roles
    If r = "" Then Exit Forall
    role = Strright(r,"[")
    role = Strleft(role,"]")
    If oEntry.IsRoleEnabled(role) Then
     Call cEntry.EnableRole(role)
    End If
   End Forall
  End If
  Set oEntry = oACL.GetNextEntry(oEntry)
 Wend
 
 Call cACL.Save
 Print "ACL Clone Completed"
End Sub


This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal